const formatTime = date => {
    const year = date.getFullYear()
    const month = date.getMonth() + 1
    const day = date.getDate()
    const hour = date.getHours()
    const minute = date.getMinutes()
    const second = date.getSeconds()

    return `${[year, month, day].map(formatNumber).join('-')} ${[hour, minute, second].map(formatNumber).join(':')}`
}

const formatNumber = n => {
    n = n.toString()
    return n[1] ? n : `0${n}`
}

const formatter = (type, value) => {
    if (type === 'year') {
        return `${value}年`;
    }
    if (type === 'month') {
        return `${value}月`;
    }
    return value;
}
const formattterDay = (date) => {
    let year = date.getFullYear(); //  返回的是年份
    let month = date.getMonth() + 1; //  返回的月份上个月的月份，记得+1才是当月
    let dates = date.getDate();
    if (month < 10) month = "0" + month;
    if (date < 10) date = "0" + date;
    let time = year + "-" + month + "-" + dates
    return time
}

module.exports = {
    formatTime,
    formatter,
    formattterDay
}